﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net;
using System.Configuration;

namespace VehicleManagement.ControllersServices
{
    public class Utility
    {
        public bool SendEmail(string address,string subject,string text)
        {
            try
            {
                string userName = ConfigurationManager.AppSettings["EmailUserName"];
                string password = ConfigurationManager.AppSettings["EmailPassword"];
                string host = ConfigurationManager.AppSettings["EmailHost"];

                SmtpClient client = new SmtpClient();
                client.Host = host;
                client.UseDefaultCredentials = false;
                client.Credentials = new NetworkCredential(userName, password);
                client.DeliveryMethod = SmtpDeliveryMethod.Network;

                System.Net.Mail.MailMessage message = new MailMessage(address, text);
                message.Subject = subject;
                message.Body = password;
                message.BodyEncoding = System.Text.Encoding.UTF8;
                message.IsBodyHtml = true;
  
                client.Send(message);

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}